package Test;

import com.pojo.Customer;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
package Test;

import com.pojo.Customer;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
package Test;

import com.pojo.Customer;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJobs("teacher");
        List<Customer> customers = sqlSession.selectList("findCustomerByNameAndJobs", customer);
        for (Customer cust : customers) {
            System.out.println(cust);
        }
        sqlSession.close();
        sqlSession.commit();
    }

    @Test
    public void updateCustomerByTest() {
import java.util.ArrayList;
import java.util.List;

        public class CustomerTest {
            @Test
            public void findCustomerByNameAndJobsTest() {
                SqlSession sqlSession = MyBatisUtils.getSqlSession();
                Customer customer = new Customer();
                customer.setUsername("jack");
                customer.setJobs("teacher");
                List<Customer> customers = sqlSession.selectList("findCustomerByNameAndJobs", customer);
                for (Customer cust : customers) {
                    System.out.println(cust);
                }
                sqlSession.close();
                sqlSession.commit();
            }

            @Test
            public void updateCustomerByTest() {
import java.util.ArrayList;
import java.util.List;

                public class CustomerTest {
                    @Test
                    public void findCustomerByNameAndJobsTest() {
                        SqlSession sqlSession = MyBatisUtils.getSqlSession();
                        Customer customer = new Customer();
                        customer.setUsername("jack");
                        customer.setJobs("teacher");
                        List<Customer> customers = sqlSession.selectList("findCustomerByNameAndJobs", customer);
                        for (Customer cust : customers) {
                            System.out.println(cust);
                        }
                        sqlSession.close();
                        sqlSession.commit();
                    }

                    @Test
                    public void updateCustomerByTest() {
                        // p:37页
                        SqlSession sqlSession = MyBatisUtils.getSqlSession();
                        Customer customer = new Customer();
                        Customer.setId(3);
                        Customer.setPhone("13311111136");
                        customer.setId(3);
                        customer.setPhone("13311111136");
                        customer.setUsername("jack");
                        int rows = sqlSession.update("updateByPrimaryKeySelective", customer);
                        customer.setJobs("teacher");
                        List<Customer> customers = sqlSession.selectList("findCustomerByNameAndJobs", customer);
                        if (rows > 0) {
                        } else {

                        }
                        sqlSession.close();
                        sqlSession.commit();
                        for (Customer cust : customers) {
                            System.out.println(cust);
                        }
                    }
                    @Test
                    public void findByArrayTest() {
                        SqlSession sqlSession = MyBatisUtils.getSqlSession();
                        Integer [] roleIds = {1,2,3};
                        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.selectByRoleIds", roleIds);
                        for (Customer customer : customers) {
                            System.out.println(customer);
                        }
                        sqlSession.close();
                    }

                    @Test
                    public void findByListTest() {
                        SqlSession sqlSession = MyBatisUtils.getSession();
                        List<Integer> ids = new ArrayList<Integer>();
                        ids.add(1);
                        ids.add(2);
                        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.selectByIds", ids);
                        for (Customer customer : customers){
                            System.out.println(customer);
                        }
                        sqlSession.close();
                    }
                }